/**
 * Carnegie Mellon University
 * School of Computer Science
 * MSIT eBusiness Technology
 * 
 * Team 8 - Infinity (2011 Spring)
 * infinity-team8@googlegroups.com
 * 
 * Professor: Jeffrey L. Eppinger
 * Program Faculty: Sujata Telang
 */

package formbean;

import java.util.ArrayList;
import java.util.List;

import org.mybeans.form.FormBean;

public class EmployeeDepositCheckForm extends FormBean {
	private String amount;
	private String userName;
		
	public String getAmount() { return amount; }
	
	public void setAmount(String s) { amount = s.trim(); }
	
	public String getUserName() {
		return userName;
	}
	public void setUserName(String userName) {
		this.userName = userName;
	}
	
	public List<String> getValidationErrors() {
		List<String> errors = new ArrayList<String>();
		
		if (amount == null || amount.length() == 0) {
			errors.add("Amount is required");
		}
		
		double inputAmount = 0;
		
		try {
			inputAmount = Double.parseDouble(amount);
		} catch (NumberFormatException e) {
			errors.add("Amount needs to be numeric");
		}
		
		if (errors.size() > 0) {
			return errors;
		}
		
		if (inputAmount <= 0) {
			errors.add("Positive amount is required");
		}
		
		if (errors.size() > 0) {
			return errors;
		}
		
		if (!amount.matches("[0-9]{0,15}.[0-9]{0,2}")) {
			errors.add("Amount can only have up to two decimal points");
		}

		return errors;
	}
}
